//
//  MTCHomePageViewController.m
//  ERP
//
//  Created by goldeney on 15/6/3.
//  Copyright (c) 2015年 ShangHai Goldeneye Techonology Co.,Ltd. All rights reserved.
//

#import "MTCHomePageViewController.h"
#import "MTCHomePageBigViewCell.h"
#import "MTCHomePageSmailViewCell.h"
#import "GEProgressCollectionViewCell.h"
#import "MTCHomePageHeaderViewCell.h"
#import "MTCHomePageClienterCell.h"

#import "Charts-Swift.h"
#import "NSDictionary+DataFormat.h"
#import "DateTimeFormat.h"

#import "MTCContractListViewController.h"
#import "MTCCreateContractViewController.h"
#import "MTCClienterViewController.h"
#import "MTCCraeteClienterViewController.h"

static NSString *const CellIdentifierBig = @"MTCHomePageBigViewCell";
static NSString *const CellIdentifierSmail = @"MTCHomePageSmailViewCell";
static NSString *const ClienterIdentifier = @"MTCHomePageClienterCell";
static NSString *const CellIdentifierHeader = @"MTCHomePageHeaderViewCell";
static NSString *const progressIdentifier = @"GEProgressCollectionViewCell";
static NSString *const RAMCollectionViewFlemishBondHeaderKind = @"RAMCollectionViewFlemishBondHeaderKind";

@interface MTCHomePageViewController ()

@property (nonatomic, strong) NSMutableArray *photosArray;

@end

@implementation MTCHomePageViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setTitle: @"营销合同"];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.collectionView registerClass:[MTCHomePageBigViewCell class] forCellWithReuseIdentifier:CellIdentifierBig];
    [self.collectionView registerClass:[MTCHomePageSmailViewCell class] forCellWithReuseIdentifier:CellIdentifierSmail];
    [self.collectionView registerClass:[MTCHomePageHeaderViewCell class] forCellWithReuseIdentifier:CellIdentifierHeader];
    [self.collectionView registerClass:[GEProgressCollectionViewCell class] forCellWithReuseIdentifier:progressIdentifier];
    [self.collectionView registerClass:[MTCHomePageClienterCell class] forCellWithReuseIdentifier:ClienterIdentifier];

    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = ThemeColorBackgroundGary;
}

#pragma mark UICollectionView

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 4;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 1) {
        return 5;
    } else if (section == 3) {
        return 2;
    }
    return 1;
}

- (CGFloat)sectionSpacingForCollectionView:(UICollectionView *)collectionView
{
    return 5.f;
}

- (CGFloat)minimumInteritemSpacingForCollectionView:(UICollectionView *)collectionView
{
    return 5.f;
}

- (CGFloat)minimumLineSpacingForCollectionView:(UICollectionView *)collectionView
{
    return 5.f;
}

- (UIEdgeInsets)insetsForCollectionView:(UICollectionView *)collectionView
{
    return UIEdgeInsetsMake(7.f, 5.f, 5.f, 5.f);
}

- (CGSize)collectionView:(UICollectionView *)collectionView sizeForLargeItemsInSection:(NSInteger)section
{
    if (section == 0) {
        return CGSizeMake(SuperWidth/2 - 15/2, 100);
    } else if (section == 1) {
        return CGSizeMake(SuperWidth/2 - 15/2, 180);
    } else if (section == 2) {
        return CGSizeMake(SuperWidth/2 - 15/2, 80);
    } else {
        return CGSizeMake(SuperWidth/2 - 15/2, 236);
    }
}

- (CGFloat)sectionHeaderForCollectionViewHeight:(UICollectionView *)collectionView indexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) return -4;
    return -10;
}

- (CGFloat)reorderingItemAlpha:(UICollectionView *)collectionview
{
    return 0.3f;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0){
        MTCHomePageHeaderViewCell*cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:
                                          CellIdentifierHeader forIndexPath:indexPath];
        cell.titleLable.text = @"合同管理";
        cell.imageView.image = [UIImage imageNamed:@"contract_gl_icon"];
        return cell;
        
    } else if (indexPath.section == 1) {
        //合同功能选项
        if (indexPath.item == 0) {
            MTCHomePageBigViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifierBig forIndexPath:indexPath];
            cell.titleLable.text = @"新增合同";
            cell.describeLable.text = @"创建新合同";
            cell.imageView.image = [UIImage imageNamed:@"contract_xz_icon"];
            return cell;
            
        } else if (indexPath.item == 1) {
            MTCHomePageSmailViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifierSmail forIndexPath:indexPath];
            cell.titleLable.text = @"历史合同";
            cell.describeLable.text = @"查看所有合同";
            cell.imageView.image = [UIImage imageNamed:@"contract_lsht_icon"];
            return cell;
            
        } else if (indexPath.item == 2) {
            MTCHomePageSmailViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifierSmail forIndexPath:indexPath];
            cell.titleLable.text = @"合同审核";
            cell.describeLable.text = @"查看审核合同";
            cell.imageView.image = [UIImage imageNamed:@"contract_sh_icon"];
            return cell;
            
        }  else if (indexPath.item == 3) {
            MTCHomePageSmailViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifierSmail forIndexPath:indexPath];
            cell.titleLable.text = @"合同分发";
            cell.describeLable.text = @"分发合同到站";
            cell.imageView.image = [UIImage imageNamed:@"contract_ff_icon"];
            return cell;
            
        }  else if (indexPath.item == 4) {
            MTCHomePageSmailViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifierSmail forIndexPath:indexPath];
            cell.titleLable.text = @"合同授权";
            cell.describeLable.text = @"查看授权合同";
            cell.imageView.image = [UIImage imageNamed:@"contract_sq_icon"];
            return cell;
        }
        
    } else if (indexPath.section == 2) {
        MTCHomePageHeaderViewCell*cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifierHeader forIndexPath:indexPath];
        cell.titleLable.text = @"客户管理";
        cell.imageView.image = [UIImage imageNamed:@"contract_khgl_icon"];
        return cell;
        
    } else if (indexPath.section == 3) {
        if (indexPath.item == 0) {
            MTCHomePageClienterCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:ClienterIdentifier forIndexPath:indexPath];
            cell.titleLable.text = @"客户档案";
            cell.describeLable.text = @"客户信息新增查看";
            cell.imageView.image = [UIImage imageNamed:@"contract_khda_icon"];
            return cell;
            
        }  else if (indexPath.item == 1) {
            MTCHomePageClienterCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:ClienterIdentifier forIndexPath:indexPath];
            cell.titleLable.text = @"客户新增";
            cell.describeLable.text = @"创建新客户信息";
            cell.imageView.image = [UIImage imageNamed:@"contract_xzyh_icon"];
            return cell;
        }
    }
    return nil;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1 && indexPath.item == 0) { //合同新增
        MTCCreateContractViewController *viewController = [[MTCCreateContractViewController alloc] init];
        [self.navigationController pushViewController:viewController animated:YES];
        
    } else if (indexPath.section == 1 &&indexPath.item == 1) { //历史合同
//        MTCContractListViewController *viewController = [[MTCContractListViewController alloc] initWithContractListType:ContractListAll];
//        [self.navigationController pushViewController:viewController animated:YES];
        
    } else if (indexPath.section == 1 &&indexPath.item == 2) { //合同审核
//        MTCContractListViewController *viewController = [[MTCContractListViewController alloc] initWithContractListType:ContractListSH];
//        [self.navigationController pushViewController:viewController animated:YES];
        
    } else if (indexPath.section == 1 &&indexPath.item == 3) { //合同分发
//        MTCContractListViewController *viewController = [[MTCContractListViewController alloc] initWithContractListType:ContractListFF];
//        [self.navigationController pushViewController:viewController animated:YES];
        
    } else if (indexPath.section == 1 &&indexPath.item == 4) { //合同授权
//        MTCContractListViewController *viewController = [[MTCContractListViewController alloc] initWithContractListType:ContractListSQ];
//        [self.navigationController pushViewController:viewController animated:YES];
        
    } else if (indexPath.section == 3 &&indexPath.item == 0) { //客户档案
        MTCClienterViewController *viewController = [[MTCClienterViewController alloc] init];
        [self.navigationController pushViewController:viewController animated:YES];
        
    } else if (indexPath.section == 3 &&indexPath.item == 1) { //客户新增
        MTCCraeteClienterViewController *viewController = [[MTCCraeteClienterViewController alloc] init];
        [self.navigationController pushViewController:viewController animated:YES];
    }
}


#pragma mark
#pragma mark - UIAlertView

- (void)sendAlertView:(NSString*)message
{
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"温馨提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    alert.alertViewStyle=UIAlertViewStyleDefault;
    [alert show];
}

@end

